package com.home.fansea.service.impl;

import com.home.fansea.config.MinioConfig;
import com.home.fansea.service.IMinioService;
import com.home.fansea.utils.MinioClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;


/**
 * @Projectname: minio-mode
 * @Filename: MinIoService
 * @Author: peggy
 * @Data:2023/6/5 12:30
 * @Description: TODO
 */
@Service
public class MinioServiceImpl implements IMinioService {
    @Autowired
    private MinioClientUtils minioClientUtils;

    @Autowired
    private MinioConfig minioConfig;

    @Override
    public String upload(MultipartFile file) {
        String objectName = minioClientUtils.upload(file);
        return minioClientUtils.getResAccessUrl(objectName);
    }

    @Override
    public String upload(String fileName) {
        String objectName = minioClientUtils.upload(fileName);
        return minioClientUtils.getResAccessUrl(objectName);
    }

    @Override
    public String upload(byte[] bytes, String extension) {
        String objectName = minioClientUtils.upload(bytes, extension);
        return minioClientUtils.getResAccessUrl(objectName);
    }


    @Override
    public boolean delete(String fileName) {
        return minioClientUtils.remove(fileName);
    }

    @Override
    public void download(String fileName, HttpServletResponse res) {
        minioClientUtils.download(fileName, res);
    }

    @Override
    public boolean isMinioFileService() {
        return minioClientUtils.isMinioFileService();
    }

    @Override
    public String getServiceUrl() {
        return minioConfig.getEndpoint();
    }
}
